﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_JDSSInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Panel ShowPro = (Panel)FindControl("ShowPro");
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "ZS_XZSS";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["ID"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            }
            Persistence1.BindControl = ShowPro;
            BindData();
            Button btnUpload = (Button)FindControl("btnUpload");
            btnUpload.Click += new EventHandler(btnUpload_Click);
        }
        
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            TextBox txtPNID = (TextBox)FindControl("txtPNID");
            TextBox txtTYPE = (TextBox)FindControl("txtTYPE");
            Label 征收决定号 = (Label)FindControl("征收决定号");
            Label Label1 = (Label)FindControl("Label1");
            DropDownList ddl在审状态 = (DropDownList)FindControl("ddl在审状态");
            if (!string.IsNullOrEmpty(HttpContext.Current.Request["PNID"])) {
                if (string.IsNullOrEmpty(txtPNID.Text)) {
                    txtPNID.Text = HttpContext.Current.Request["PNID"];
                } 
            }
            if (!string.IsNullOrEmpty(HttpContext.Current.Request["DZ"]))
            {
                if (string.IsNullOrEmpty(txtTYPE.Text))
                {
                    txtTYPE.Text = HttpContext.Current.Request["DZ"];
                }
            }
            if (!string.IsNullOrEmpty(征收决定号.Text)) {
                EluZSProvider.Prono prono = _EluZSDataProvider.GetProno(HttpContext.Current.Request["PNID"]);
                征收决定号.Text = prono.征收许可证号;
            }
            string tt = HttpContext.Current.Request["type"];
            if (!string.IsNullOrEmpty(tt)) {
                ddl在审状态.SelectedIndex = Convert.ToInt32(tt);
                if (tt == "0") { Label1.Text = "一审诉讼"; }
                else if (tt == "1") { Label1.Text = "二审诉讼"; }
                else if (tt == "2") { Label1.Text = "再审诉讼"; }
            }
        }
        protected void BindData() {
            Button btnSave = (Button)FindControl("btnSave");
            Button btnReturn = (Button)FindControl("btnReturn");
            btnSave.Click += new EventHandler(btnSave_Click);
            btnReturn.Click+=new EventHandler(btnReturn_Click);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Persistence1.Update();
            //HttpContext.Current.Response.Redirect("ZS_JDSSInfo.aspx?PNID=" + HttpContext.Current.Request["PNID"] + "&ID=" + Persistence1.KeyValue + "&DZ=" + HttpContext.Current.Request["DZ"] + "&type=" + HttpContext.Current.Request["type"]);
            string url = "ZS_JDSSInfo.aspx?PNID=" + HttpContext.Current.Request["PNID"] + "&ID=" + Persistence1.KeyValue + "&DZ=" + HttpContext.Current.Request["DZ"] + "&type=" + HttpContext.Current.Request["type"];
            base.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功');location.href='"+url+"'</script>");
        }
        protected void btnReturn_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect("ZS_JDSS.aspx?dz=" + HttpContext.Current.Request["DZ"]);
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string strID = base.Page.Request["ID"];
            if (string.IsNullOrEmpty(strID))
            {
                base.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请先保存数据');</script>");
                return;
            }
            //设置文件上传的关键字段
            if (!string.IsNullOrEmpty(strID))
            {
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}','{3}','{4}');</script>", "412",
                    base.Page.Request["ID"], base.Page.Request["ID"], HttpContext.Current.Request["ID"], "");
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }
    }
}


